<?php
namespace app\models;

use Yii;
use yii\db\Query;
/**
 * This is the model class for table "{{%cart}}".
 *
 * @property integer $id
 * @property integer $uid
 * @property integer $create_at
 * @property integer $status
 */
class BaseGoodTypes extends \yii\db\ActiveRecord {
    
     /**
     * @inheritdoc
     */
    public static function countBaseGoodQgHy($type) {
        
        if($type == 'qg'){
             $sql = 'select sp_id,count(sp_id),max(cgjg) from dh_base_goods_qg group by sp_id';
             $basegoodsnum = BaseGoodTypes::findBySql($sql)->asArray()->all();
        }elseif ($type == 'hy') {
             $sql = 'select sp_id,count(sp_id),min(sczdj) from dh_base_goods_hy group by sp_id';
             $basegoodsnum = BaseGoodTypes::findBySql($sql)->asArray()->all();
        }
        
        return $basegoodsnum;
    }
    
    public static function listBaseGoods() {
        
             $sql = 'select * from dh_base_goods where is_deleted=0';
             $total = BaseGoodTypes::findBySql($sql)->asArray()->all();
        
        return $total;
    }
    
     public static function listBaseType($type) {
            if($type == 'all'){
                $sql = 'select * from dh_base_type where is_deleted=0';
                $basetype = BaseGoodTypes::findBySql($sql)->asArray()->all();
            }elseif ($type =='one') {
                $sql = 'select * from dh_base_type where is_deleted=0 and category=0';
                $basetype = BaseGoodTypes::findBySql($sql)->asArray()->all();
        }
             
        
        return $basetype;
    }
    
     public static function listBaseBrand() {
           
            $sql = 'select * from dh_base_brand where is_deleted=0 limit 10';
            $basebrand = BaseGoodTypes::findBySql($sql)->asArray()->all();

        return $basebrand;
    }
    
    public static function upBasegoods($id) {
           
            $sql = 'select id from dh_base_type where is_deleted=0 and category='.$id;
            $basegoods = BaseGoodTypes::findBySql($sql)->asArray()->all();
             foreach ($basegoods as $value) {
                $tag[] = $value['id'];
            }
//            print_r($tag);die();
        return $basegoods;
    }
    
    
    
    
    
    
    
    
    
}


?>